﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Net;
using XcoAppSpaces.Security.Basic;

namespace test.XcoAppSpaces.Security.Basic
{
	[TestFixture]
	public class testCredentialsExtensions
	{
		[Test]
		public void ValidCredentialValidAddress()
		{
			NetworkCredential cred = new NetworkCredential("test", "test");
			var xcocred = cred.GetXcoClientCredentials("localhost:9000");
			Assert.IsNotNull(xcocred);
			Assert.AreEqual("test", xcocred.User);
			Assert.AreEqual(PasswordUtil.CreatePasswordHash("test"), xcocred.Password);
		}

		[Test]
		public void ValidCredentialNoAddress()
		{
			NetworkCredential cred = new NetworkCredential("test", "test");
			var xcocred = cred.GetXcoClientCredentials(null);
			Assert.IsNotNull(xcocred);
			Assert.AreEqual("test", xcocred.User);
			Assert.AreEqual(PasswordUtil.CreatePasswordHash("test"), xcocred.Password);
		}

		[Test]
		public void ValidCredentialWrongAddress()
		{
			NetworkCredential cred = new NetworkCredential("test", "test");
			var xcocred = cred.GetXcoClientCredentials(".\\invalid$\\msmqueueaddress");
			Assert.IsNotNull(xcocred);
			Assert.AreEqual("test", xcocred.User);
			Assert.AreEqual(PasswordUtil.CreatePasswordHash("test"), xcocred.Password);
		}

		[Test]
		public void CredentialNull()
		{
			NetworkCredential cred = null;
			var xcocred = cred.GetXcoClientCredentials(".\\invalid$\\msmqueueaddress");
			Assert.IsNull(xcocred);
		}
	}
}
